<template>
    <div class="HomeWin" @click.stop="HomeWinStartShow = false">
        <div class="HomeWin-background">
            <img class="HomeWin-background-img" :src="`./images/login/${imgNum}.jpg`" />
        </div>
        <div class="HomeWin-main">
            <!-- <div class="HomeWin-menu">
        <home-win-menu :list="MenuList" @change="MenuActive" />
      </div>-->
            <!--  include:包含    exclude:排除 -->
            <!--
                <keep-alive :include="getKeepAlive" :max="256">
                <router-view></router-view>
            </keep-alive>
            -->
            <router-view v-slot="{ Component }">
                <keep-alive :include="getKeepAlive" :max="256">
                    <component :is="Component" />
                </keep-alive>
            </router-view>
        </div>
        <div class="HomeWin-footer">
            <div class="HomeWin-footer-left" @click.stop="HomeWinStartShow = !HomeWinStartShow">
                <i class="fa fa-windows"></i>
            </div>
            <div class="HomeWin-footer-body">
                <div @click.stop="historyRightMove" class="HomeWin-footer-body-left">
                    <i class="el-icon-caret-left"></i>
                </div>
                <div class="HomeWin-footer-body-history" ref="homeHistory">
                    <transition-group name="router-history-anim" tag="div" ref="homeHistoryList" class="HomeWin-footer-body-history-list"
                        :style="{ width: `${historyWidth}px`, left: `${historyLeft}px` }">
                        <div class="HomeWin-footer-body-history-item" v-for="(item, index) in historyList" :key="item.id" :class="
                item.active ? 'HomeWin-footer-body-history-item-active' : ''" @click.stop="MenuActive(item.route)">
                            <div class="HomeWin-footer-body-history-item-icon">
                                <div v-if="item.img">
                                    <img :src="item.img" />
                                </div>
                                <div v-else :style="`background-color:${item.icon_color}`">
                                    <i :class="item.icon"></i>
                                </div>
                            </div>
                            <div class="HomeWin-footer-body-history-item-title">
                                {{ item.title }}
                            </div>
                            <div v-show="historyList.length > 1" class="HomeWin-footer-body-history-item-close" @click.stop="DelHistoryMenu(index)">
                                <i class="el-icon-close"></i>
                            </div>
                            <div class="HomeWin-footer-body-history-item-show"></div>
                        </div>
                    </transition-group>
                </div>
                <div @click.stop="historyLeftMove" class="HomeWin-footer-body-right">
                    <i class="el-icon-caret-right"></i>
                </div>
            </div>
            <div class="HomeWin-footer-right">
                <div>{{ dateTime }}</div>
                <div>
                    <i class="el-icon-chat-line-square"></i>
                </div>
            </div>
        </div>
        <transition name="HomeWinStart" @click.stop>
            <div class="HomeWin-start" v-show="HomeWinStartShow" @click.stop>
                <div class="HomeWin-start-left" @click.stop>
                    <menu-list :active-menu="activeMenu" @change="MenuActive" />
                </div>
                <div class="HomeWin-start-right" @click.stop>
                    <div class="HomeWin-start-right-top">
                        <!-- 开始菜单快捷栏顶部 -->
                        <div class="HomeWin-start-right-top-logo">
                            <!-- 系统logo -->
                            <img src="../../../../assets/images/phq-logo.png" />
                            <div>{{ config.appName }}</div>
                        </div>
                        <div class="HomeWin-start-right-top-body">
                            <!--  登录用户 -->
                            <div class="HomeWin-start-right-top-body-user">
                                <!-- @change="HomeWinStartShow = false" -->
                                <user class-name="user-win" />
                            </div>
                        </div>
                    </div>
                    <div class="HomeWin-start-right-body">
                        <!-- 开始菜单快捷栏 -->
                    </div>
                </div>
            </div>
        </transition>
    </div>
</template>

<script lang="ts">
import { defineComponent } from "vue";
import setup from "../Home";
import utils from "@/lib/utils";
import MenuList from "@/views/app/home/components/MenuList";
import User from "@/views/app/home/components/User.vue";
export default defineComponent({
    name: "HomeWin",
    setup,
    data(): any {
        return {
            imgNum: 10,
            dateTime: "",
            intervalId: null,
        };
    },
    components: { MenuList, User },
    mounted() {
        this.imgNum = utils.getRandom(0, 11);
        this.getDateTime();
        document.getElementById("app-loading")?.remove();
        document.getElementById("app-loading-css")?.remove();
    },
    unmounted() {
        if (this.intervalId) {
            clearInterval(this.intervalId);
            this.intervalId = null;
        }
    },
    methods: {
        getDateTime() {
            const getDate: any = (num: number) => {
                if (num < 10) {
                    return "0" + num;
                } else {
                    return num;
                }
            };
            this.intervalId = setInterval(() => {
                const time = new Date();
                const Y = time.getFullYear();
                const M = getDate(time.getMonth() + 1);
                const d = getDate(time.getDate());
                const h = getDate(time.getHours());
                const m = getDate(time.getMinutes());
                const s = getDate(time.getSeconds());
                this.dateTime = `${Y}-${M}-${d} ${h}:${m}:${s}`;
            }, 1000);
        },
    },
});
</script>


<style scoped lang="scss">
//首页
.HomeWin {
    height: 100%;

    &-background {
        position: fixed;
        width: 100%;
        height: 100%;
        z-index: -99;

        &-img {
            width: 100%;
            height: 100%;
        }
    }
    &-main {
        position: relative;
        z-index: 1;
        height: calc(100% - 35px);
        background-color: rgba(255, 255, 255, 0.6);
        overflow-x: hidden;
        overflow-y: auto;
    }
    &-footer {
        position: relative;
        z-index: 3;
        background-color: rgba(0, 0, 0, 0.7);
        height: 35px;
        color: #ffffff;
        display: flex;
        justify-content: space-between;
        align-items: center;
        &-left {
            color: #ffffff;
            width: 35px;
            font-size: 18px;
            height: 100%;
            align-items: center;
            justify-content: center;
            display: flex;
            &:hover {
                cursor: pointer;
                color: $primary-color;
                background-color: rgba(255, 255, 255, 0.2);
            }
        }
        &-body {
            width: calc(100% - 200px);
            //background-color:red;
            height: 100%;
            display: flex;
            align-items: center;
            &-left,
            &-right {
                display: flex;
                align-items: center;
                justify-content: center;
                font-size: 18px;
                width: 15px;
                height: 100%;
                background-color: rgba(255, 255, 255, 0.2);
                color: #828283;
                cursor: pointer;
                overflow: hidden;
                transition: all 0.3s;
                &:hover {
                    color: $primary-color;
                    background-color: rgba(255, 255, 255, 0.3);
                }
            }
            &-history {
                width: calc(100% - 30px);
                height: 100%;
                overflow: hidden;
                &-list {
                    height: 100%;
                    position: relative;
                    transition: all 0.5s;
                    font-size: 14px;
                }
                &-item {
                    height: 100%;
                    position: relative;
                    display: inline-block;
                    margin: 0 2px;
                    padding: 0 5px;
                    cursor: pointer;
                    color: #fff;
                    &:first-child {
                        margin-left: 0;
                    }
                    &:last-child {
                        margin-right: 0;
                    }
                    &:hover {
                        background-color: rgba(255, 255, 255, 0.2);
                        & .HomeWin-footer-body-history-item-show {
                            //transform:scale(1.2);
                            height: 5px;
                            width: 106%;
                            left: -3%;
                        }
                    }
                    &-icon {
                        display: inline-block;
                        height: 18px;
                        width: 18px;
                        overflow: hidden;
                        border-radius: 3px;
                        position: relative;
                        top: 7px;
                        color: #fff;
                        & > div {
                            width: 100%;
                            height: 100%;
                            display: flex;
                            align-items: center;
                            justify-content: center;
                            & > img {
                                height: 100%;
                                width: 100%;
                            }
                            & > i {
                                position: relative;
                                top: 0;
                            }
                        }
                    }
                    &-title {
                        display: inline-block;
                        margin-left: 3px;
                        position: relative;
                        word-break: keep-all; /* 不换行 */
                        white-space: nowrap; /* 不换行 */
                        top: 3px;
                    }
                    &-close {
                        position: relative;
                        top: 4px;
                        display: inline-block;
                        margin-left: 3px;
                        transition: all 0.3s;
                        &:hover {
                            color: #ff0000;
                            transform: scale(1.5) rotate(90deg);
                        }
                    }
                    &-active {
                        background-color: rgba(255, 255, 255, 0.4);
                        color: #fff;
                    }
                    &-show {
                        position: absolute;
                        height: 3px;
                        background-color: $primary-color;
                        bottom: 0;
                        left: 0;
                        width: 100%;
                        transition: all 0.5s;
                    }
                }
            }
        }
        &-right {
            display: flex;
            justify-content: flex-end;
            align-items: center;
            height: 100%;
            & > div {
                &:first-child {
                    align-items: center;
                    justify-content: center;
                    display: flex;
                    font-size: 12px;
                    width: 130px;
                    height: 100%;
                    &:hover {
                        cursor: pointer;
                        // color: $primary-color;
                        background-color: rgba(255, 255, 255, 0.2);
                    }
                }
                &:last-child {
                    align-items: center;
                    justify-content: center;
                    display: flex;
                    font-size: 23px;
                    width: 35px;
                    height: 100%;
                    &:hover {
                        cursor: pointer;
                        // color: $primary-color;
                        background-color: rgba(255, 255, 255, 0.2);
                    }
                }
            }
        }
    }
    &-start {
        position: fixed;
        z-index: 1999;
        left: 0;
        bottom: 35px;
        background-color: rgba(0, 0, 0, 0.6);
        min-width: 680px;
        width: 60%;
        height: 60%;
        //box-shadow: 0 0 5px $text-primary-color;
        display: flex;
        &-left {
            width: 240px;
            overflow-x: hidden;
            overflow-y: auto;
        }
        &-right {
            //background-color:salmon;
            width: calc(100% - 240px);

            &-top {
                height: 50px;
                display: flex;
                justify-content: space-between;
                background-color: rgba(0, 0, 0, 0.1);
                //border-bottom:1px rgba(255, 255, 255, 0.1) solid;
                &-logo {
                    height: 100%;
                    display: flex;
                    align-items: center;
                    padding: 0 5px;
                    & > img {
                        max-height: 90%;
                    }
                    & > div {
                        padding-left: 5px;
                        font-size: 28px;
                        font-weight: bold;
                        color: rgba(255, 255, 255, 0.9);
                        text-shadow: 0 0 5px rgba(255, 255, 255, 0.8);
                    }
                }
                &-body {
                    height: 100%;
                    display: flex;
                    align-items: center;
                    justify-content: flex-end;
                    &-user {
                        height: 100%;
                        //border-left:1px rgba(255, 255, 255, 0.1) solid;
                    }
                }
            }
            &-body {
                overflow-x: hidden;
                overflow-y: auto;
                height: calc(100% - 50px);
            }
        }
    }

    .HomeWinStart-enter-active {
        animation: HomeWinStart-in 0.3s;
    }

    .HomeWinStart-leave-active {
        animation: HomeWinStart-in 0.3s reverse;
    }

    @keyframes HomeWinStart-in {
        0% {
            left: -60%;
        }
        100% {
            left: 0;
        }
    }
}
</style>